import { delToken, setToken } from "@/utils/auth"
import request from "@/utils/request"

export function loginAction (payload) {
  return async (dispatch, getState) => {
    const res = await request.post('/authorizations', payload)
    console.log(res)
    dispatch({ type: 'login/token', payload: res.data.token })
    setToken(res.data.token)
  }
}

export const logOutAction = (payload) => {
  return async (dispatch, getState) => {
    /**
     * 1.删除token
     * 2.删除登陆人信息user
     * 3.发请求退出
     */
    dispatch({ type: 'login/delToken' })
    delToken()
    dispatch({ type: 'user/del' })
  }
}